import axios from "axios";
import * as storage from "./storage";

const service = axios.create();

// 请求拦截器，用于添加自定义请求头信息
service.interceptors.request.use(
  (req) => {
    if (storage.getItem("XX-see")) {
      req.headers["XX-see"] = storage.getItem("XX-see");
    }
    if (storage.getItem("mti")) {
      req.headers.mti = storage.getItem("mti");
    }
    // req.headers.Authorization = `Bearer ${getToken()}`
    // req.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
    return req;
  },
  (err) => {
    return Promise.reject(err);
  }
);

// 响应拦截器
service.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);

export default service;
